package tasks;


import Main.*;
import java.io.File;
import java.io.FilenameFilter;

/**
 * Find task files in folder specified in settings.ini
 * @author zem
 */
public class TaskFinder {
    
    

    /**
     * @param TaskName Path to every task located in task folder which is specified in settings.ini
     * @param NumberOfFileTasks number of files with tasks
     */
    
    public void Find(){
        
        //getting files with tasks
        Parameters.TotalTasks=0;
        File f1 = new File(Parameters.TaskFolder);
        int i=0;
        String[] ls;
        FilenameFilter filter = new TaskFilter();
        ls = f1.list(filter);
        
        for (i = 0; ls != null && i < ls.length;  i++) {
            //checking if file is not already done:
            boolean task_done=false; //new task
            if(Parameters.DeleteTaskWhenDone==0){
            if(Parameters.MoveDoneTask==0 |Parameters.MoveFailedTask==0){
                for(int j=0; j<Parameters.TasksDone; j++){
                        if(ls[i].equals(Parameters.AdrOfDoneTasks[j])){task_done=true; j=Parameters.TasksDone;}
                        }

            }
            }

            if(!task_done){ //if new task

            //adding task
            Parameters.TaskName[Parameters.TotalTasks] = ls[i];
            Parameters.taskAssignTime[Parameters.TotalTasks]= Parameters.CurrentSystemTime;
            Parameters.TotalTasks++;
            

            }

        }



    }
}

class TaskFilter implements FilenameFilter { //filter

    public boolean accept(File dir, String name) {
        return (name.endsWith(Parameters.FileTaskExtension));
    }
}
